package string;
/**
 * String replaceAll(String regex,String replacement)
 * 将当前字符串中满足正则表达式(regex)的部分替换为给定内容(replacement)
 */
public class ReplaceAllDemo {
    public static void main(String[] args) {
        String str = "abc123def456ghi";
        //将数字部分替换为#NUMBER#
        str = str.replaceAll("[0-9]+", "#NUMBER");
        System.out.println(str); //abc#NUMBERdef#NUMBERghi
        /*
            如果regex为[0-9],
            str为: abc#NUMBER#NUMBER#NUMBERdef#NUMBER#NUMBER#NUMBERghi
         */

        //和谐用语
        String regex = "(gun|sha|sb|fuck)";
        String message = "你sb,gun,fuck吧!";
        message = message.replaceAll(regex, "***");
        System.out.println(message);
    }
}
